package com.cskaoyan.controller.aftersale;

import com.cskaoyan.model.bo.PageBo;
import com.cskaoyan.model.bo.aftersale.BatchBo;
import com.cskaoyan.model.vo.BaseData;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.service.aftersale.AfterSaleService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: mjm
 * @Date: 2021/11/30
 * @Time: 20:25
 * @Description:
 */
@RestController
@RequestMapping("admin/aftersale")
public class AfterSaleController {
    @Autowired
    AfterSaleService afterSaleService;

    /**
     * @description: 售后列表
     * @param:
     * @return:
     */
    @RequiresPermissions("admin:aftersale:list")
    @GetMapping("list")
    public BaseRespVo aftersaleList(PageBo pageBo, String aftersaleSn, Short status, Integer orderId) {
        BaseData baseData = afterSaleService.aftersaleList(pageBo, aftersaleSn, status, orderId);
        return BaseRespVo.ok(baseData);
    }


    /**
     * @description: 批量通过
     * @param: {ids: [2, 1]}
     * @return: {"errno":0,"errmsg":"成功"}
     */
    @RequiresPermissions("admin:aftersale:batch-recept")
    @PostMapping("/batch-recept")
    public BaseRespVo batchRecept(@RequestBody BatchBo batchBo) {
        int affectedRows = afterSaleService.batchRecept(batchBo.getIds());
        if (affectedRows != 0) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }


    /**
     * @description: 批量拒绝
     * @param: {ids: [2, 1]}
     * @return: {"errno":0,"errmsg":"成功"}
     */
    @RequiresPermissions("admin:aftersale:batch-recept")
    @PostMapping("/batch-reject")
    public BaseRespVo batchReject(@RequestBody BatchBo batchBo) {
        int affectedRows = afterSaleService.batchReject(batchBo.getIds());
        if (affectedRows != 0) {
            return BaseRespVo.ok();
        }
        return BaseRespVo.fail();
    }


    /**
     * @description: 不允许退款
     * @param: errmsg: "订单退款失败"
     * errno: 621
     * @return:
     */
    @RequiresPermissions("admin:aftersale:refund")
    @PostMapping("refund")
    public BaseRespVo aftersaleRefund() {
        return BaseRespVo.manual(621, "订单退款失败", null);
    }
}
